//判断是否为空
const contractCount = {
    //计算税额  税额=税率*不含税金额
    countTax (taxRate, amountWithoutTax) {
        return  ((taxRate / 100) * amountWithoutTax).toFixed(2)
    },
    //计算税率  税率=税额/不含税金额  向下取整
    countTaxRate (tax, amountWithoutTax) {
        return Math.floor(tax / amountWithoutTax)
    },
    //计算合同金额  合同金额=不含税金额+税额
    countMoney (amountWithoutTax, tax) {
        let connt = ((amountWithoutTax ? parseFloat(amountWithoutTax) : amountWithoutTax)  + (tax ? parseFloat(tax) : tax))
        return parseInt(connt)
    },
    //计算物资，设备类合同金额  合同金额=不含税金额+税额+服务单位费用
    materialstMoney (amountWithoutTax, tax, serverUnitAmount) {
        let connt = (amountWithoutTax ? parseFloat(amountWithoutTax) : 0)  + (tax ? parseFloat(tax) : 0) + (serverUnitAmount ? parseFloat(serverUnitAmount) : 0)
        return connt.toFixed(2)
    },
    //计算预付款比例  预付款比例=预付款金额/合同金额*100%
    countRatio (advanceCharge, money) {
        let num
        if(money != 0) {
            num =  (advanceCharge * 100 / money).toFixed(4)
        }
        return num
    },
    //计算物资类合同税额
    materialTaxRate (contractListTableInit, serviceListTableInit, taxRate, transportTaxRate, isChange = false) {
        taxRate = taxRate ? taxRate : 0
        transportTaxRate = transportTaxRate ? transportTaxRate : 0
        if(!isChange) {
            //将合同清单数据平铺去掉删除的
            let contractListTable = []
            contractListTableInit.forEach(item=>{
                item.children.forEach(res=>{
                    contractListTable.push(res)
                })
            })
            contractListTable = contractListTable.filter(x=>x.changeType !== -1)
            const contractAmountArr = contractListTable.map(x=>parseFloat((x.amount * parseFloat(taxRate / 100) ).toFixed(2)))//合同清单金额*税率
            const contractAmount = contractAmountArr.reduce((prev, item)=>{ //计算合同清单税额
                return prev + item
            }, 0)
            let serviceListTable = serviceListTableInit
            serviceListTable = serviceListTable.filter(x=>x.changeType !== -1)
            const serviceAmountArr =  serviceListTable.map(x=>parseFloat((x.amount * parseFloat(transportTaxRate / 100) ).toFixed(2)))//服务清单金额*服务清单税率
            const serviceAmount = serviceAmountArr.reduce((prev, item)=>{ //计算服务清单清单税额
                return prev + item
            }, 0)
            const taxAmount = contractAmount + serviceAmount
            return taxAmount
        }else{
            //将合同清单数据平铺去掉删除的
            let contractListTable = []
            contractListTableInit.forEach(item=>{
                item.children.forEach(res=>{
                    contractListTable.push(res)
                })
            })
            contractListTable = contractListTable.filter(x=>x.changeType !== -1 && x.changeType !== -2)
            const contractAmountArr = contractListTable.map(x=>parseFloat((x.amountAfterChange * parseFloat(taxRate / 100) ).toFixed(2)))//合同清单金额*税率
            const contractAmount = contractAmountArr.reduce((prev, item)=>{ //计算合同清单税额
                return prev + item
            }, 0)
            let serviceListTable = serviceListTableInit
            serviceListTable = serviceListTable.filter(x=>x.changeType !== -1 && x.changeType !== -2)
            const serviceAmountArr =  serviceListTable.map(x=>parseFloat((x.amountAfterChange * parseFloat(transportTaxRate / 100) ).toFixed(2)))//服务清单清单金额*服务清单税率
            const serviceAmount = serviceAmountArr.reduce((prev, item)=>{ //计算服务清单清单税额
                return prev + item
            }, 0)
            const taxAmount = (contractAmount + serviceAmount).toFixed(2)
            return taxAmount
        }
    },
    //计算服务采购物资类合同税额
    serviceProcurementTaxRate (contractListTableInit, taxRate, isChange = false) {
        taxRate = taxRate ? taxRate : 0
        if(!isChange) {
            //将合同清单数据平铺去掉删除的
            let contractListTable = []
            contractListTableInit.forEach(item=>{
                item.children.forEach(res=>{
                    contractListTable.push(res)
                })
            })
            contractListTable = contractListTable.filter(x=>x.changeType !== -1)
            const contractAmountArr = contractListTable.map(x=>parseFloat((x.amount * parseFloat(taxRate / 100) ).toFixed(2)))//合同清单金额*税率
            const contractAmount = contractAmountArr.reduce((prev, item)=>{ //计算合同清单税额
                return prev + item
            }, 0)
            return contractAmount
        }else{
            //将合同清单数据平铺去掉删除的
            let contractListTable = []
            contractListTableInit.forEach(item=>{
                item.children.forEach(res=>{
                    contractListTable.push(res)
                })
            })
            contractListTable = contractListTable.filter(x=>x.changeType !== -1 && x.changeType !== -2)
            const contractAmountArr = contractListTable.map(x=>parseFloat((x.amountAfterChange * parseFloat(taxRate / 100) ).toFixed(2)))//合同清单金额*税率
            const contractAmount = contractAmountArr.reduce((prev, item)=>{ //计算合同清单税额
                return prev + item
            }, 0)
            return contractAmount
        }
    },
    //计算服务采购设备类合同税额
    serviceProcurementEquipTaxRate (contractListTableInit, taxRate, isChange = false) {
        taxRate = taxRate ? taxRate : 0
        if(!isChange) {
            //将合同清单数据平铺去掉删除的
            let contractListTable = contractListTableInit.filter(x=>x.changeType !== -1)
            const contractAmountArr = contractListTable.map(x=>parseFloat((x.amount * parseFloat(taxRate / 100) ).toFixed(2)))//合同清单金额*税率
            const contractAmount = contractAmountArr.reduce((prev, item)=>{ //计算合同清单税额
                return prev + item
            }, 0)
            return contractAmount
        }else{
            //将合同清单数据平铺去掉删除的
            let contractListTable = contractListTableInit.filter(x=>x.changeType !== -1 && x.changeType !== -2)
            const contractAmountArr = contractListTable.map(x=>parseFloat((x.amountAfterChange * parseFloat(taxRate / 100) ).toFixed(2)))//合同清单金额*税率
            const contractAmount = contractAmountArr.reduce((prev, item)=>{ //计算合同清单税额
                return prev + item
            }, 0)
            return contractAmount
        }
    },
    //计算设备类合同税额
    equipmentTaxRate (contractListTableInit, serviceListTableInit, taxRate, transportTaxRate, isChange = false) {
        taxRate = taxRate ? taxRate : 0
        transportTaxRate = transportTaxRate ? transportTaxRate : 0
        if(!isChange) {
            //将合同清单数据平铺去掉删除的
            let contractListTable = []
            contractListTable = contractListTableInit.filter(x=>x.changeType !== -1)
            const contractAmountArr = contractListTable.map(x=>parseFloat((x.amount * parseFloat(taxRate / 100) ).toFixed(2)))//合同清单金额*税率
            const contractAmount = contractAmountArr.reduce((prev, item)=>{ //计算合同清单税额
                return prev + item
            }, 0)
            let serviceListTable = serviceListTableInit
            serviceListTable = serviceListTable.filter(x=>x.changeType !== -1)
            const serviceAmountArr =  serviceListTable.map(x=>parseFloat((x.amount * parseFloat(transportTaxRate / 100) ).toFixed(2)))//服务清单金额*服务清单税率
            const serviceAmount = serviceAmountArr.reduce((prev, item)=>{ //计算服务清单清单税额
                return prev + item
            }, 0)
            const taxAmount = contractAmount + serviceAmount
            return taxAmount
        }else{
            //将合同清单数据平铺去掉删除的
            let contractListTable = []
            contractListTable = contractListTableInit.filter(x=>x.changeType !== -1 && x.changeType !== -2)
            const contractAmountArr = contractListTable.map(x=>parseFloat((x.amountAfterChange * parseFloat(taxRate / 100) ).toFixed(2)))//合同清单金额*税率
            const contractAmount = contractAmountArr.reduce((prev, item)=>{ //计算合同清单税额
                return prev + item
            }, 0)
            let serviceListTable = serviceListTableInit
            serviceListTable = serviceListTable.filter(x=>x.changeType !== -1 && x.changeType !== -2)
            const serviceAmountArr =  serviceListTable.map(x=>parseFloat((x.amountAfterChange * parseFloat(transportTaxRate / 100) ).toFixed(2)))//服务清单清单金额*服务清单税率
            const serviceAmount = serviceAmountArr.reduce((prev, item)=>{ //计算服务清单清单税额
                return prev + item
            }, 0)
            const taxAmount = contractAmount + serviceAmount
            return taxAmount
        }
    },
    //计算收入类合同税额
    incomeTaxRate (contractListTableInit, taxRate, isChange = false) {
        taxRate = taxRate ? taxRate : 0
        if(!isChange) {
            //将合同清单数据平铺去掉删除的
            let contractListTable = []
            contractListTable = contractListTableInit.filter(x=>x.changeType !== -1)
            const contractAmountArr = contractListTable.map(x=>parseFloat((x.amount * parseFloat(taxRate / 100) ).toFixed(2)))//合同清单金额*税率
            const contractAmount = contractAmountArr.reduce((prev, item)=>{ //计算合同清单税额
                return prev + item
            }, 0)
            return contractAmount
        }else{
            //将合同清单数据平铺去掉删除的
            let contractListTable = []
            contractListTable = contractListTableInit.filter(x=>x.changeType !== -1 && x.changeType !== -2)
            const contractAmountArr = contractListTable.map(x=>parseFloat((x.amountAfterChange * parseFloat(taxRate / 100) ).toFixed(2)))//合同清单金额*税率
            const contractAmount = contractAmountArr.reduce((prev, item)=>{ //计算合同清单税额
                return prev + item
            }, 0)
            return contractAmount
        }
    },
    //计算收入类合同税额
    incomeEquipTaxRate (contractListTableInit, taxRate, isChange = false) {
        taxRate = taxRate ? taxRate : 0
        if(!isChange) {
        //将合同清单数据平铺去掉删除的
            let contractListTable = []
            contractListTable = contractListTableInit.filter(x=>x.changeType !== -1)
            const contractAmountArr = contractListTable.map(x=>parseFloat((x.actualDisposalAmount * parseFloat(taxRate / 100) ).toFixed(2)))//合同清单金额*税率
            const contractAmount = contractAmountArr.reduce((prev, item)=>{ //计算合同清单税额
                return prev + item
            }, 0)
            return contractAmount
        }else{
        //将合同清单数据平铺去掉删除的
            let contractListTable = []
            contractListTable = contractListTableInit.filter(x=>x.changeType !== -1 && x.changeType !== -2)
            const contractAmountArr = contractListTable.map(x=>parseFloat((x.actualDisposalAmountAfterChange * parseFloat(taxRate / 100) ).toFixed(2)))//合同清单金额*税率
            const contractAmount = contractAmountArr.reduce((prev, item)=>{ //计算合同清单税额
                return prev + item
            }, 0)
            return contractAmount
        }
    },

}
export default contractCount